package com.qidian.mespro.controller;


import com.github.pagehelper.PageInfo;
import com.qidian.mespro.service.WorkflowService;
import com.qidianit.mes.pojo.Result;
import com.qidianit.mes.pojo.Workflow;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ author: 周晓轩
 * @ company 起点编程
 * @ time: 2025/9/18 - 16:59
 * @ Description:
 */
@RestController
@RequestMapping("/workflow")
public class WorkflowController {

    @Autowired
    private WorkflowService workflowService;

    @GetMapping("page")
    public Result<PageInfo<Workflow>> list(Workflow workflow, @RequestParam(defaultValue = "1")int page, @RequestParam(defaultValue = "10")int size){
        return workflowService.WorkflowList(workflow,page,size);
    };

    @PostMapping("/add")
    public Result<Workflow> save(@RequestBody Workflow workflow){
        return workflowService.addWorkflow(workflow);
    };

    @GetMapping("/code/{code}")
    public Result<Workflow> getByCode(@PathVariable("code") String code){
        return workflowService.selectWorkflowByCode(code);
    }

    @PutMapping("/update")
    public Result update(@RequestBody Workflow workflow){
        return workflowService.updateWorkflowById(workflow);
    };

    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Long id){
        return workflowService.deleteWorkflowById(id);
    }

    @DeleteMapping("/batchDelete")
    public Result batchDelete(Long [] id){
        return workflowService.batchDelete(id);
    };

    @GetMapping("/selectByMaterialCode")
    public Result<List<Workflow>> selectByMaterialCode(String materialCode){
        return workflowService.selectListByMaterialCode(materialCode);
    }
}
